package com.example.demo.common.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ToolsUtil {

    /**
     * @Title: returnMessage @Description: 返回格式 @param @param
     *         returnCode @param @param returnMessage @param @return
     *         设定文件 @return Map<String,Object> 返回类型 @throws
     */
    public static Map<String, Object> returnMessage(int returnCode, String returnMessage) {
        Map<String, Object> returnMap = new HashMap<String, Object>();
        returnMap.put("code", returnCode);
        returnMap.put("data", returnMessage);
        return returnMap;
    }

    public static Map<String, Object> returnMessage(int returnCode, Object returnMessage) {
        Map<String, Object> returnMap = new HashMap<String, Object>();
        returnMap.put("code", returnCode);
        returnMap.put("data", returnMessage);
        return returnMap;
    }

    /**
     * 返回分页表格信息
     * @param returnCode 状态码
     * @param count 总记录条数
     * @param msg 结果
     * @param returnData 数据
     * @return
     */
    public static Map<String, Object> returnTable(int returnCode, int count, String msg, Object returnData) {
        Map<String, Object> returnMap = new HashMap<String, Object>();
        returnMap.put("code", returnCode);
        returnMap.put("count", count);
        returnMap.put("msg", msg);
        returnMap.put("data", returnData);
        return returnMap;
    }

    /**
     * 判断列表是否为空
     *
     * @return boolean [空则返回true]
     */
    public static boolean isEmpty(List<?> list) {
        if (null == list || 0 == list.size()) {
            return true;
        }
        return false;
    }

    /**
     * 判断字符串是否为空 <功能详细描述>
     *
     * @return boolean [返回类型说明]
     * @exception throws
     *                [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    public static boolean isEmpty(String string) {
        return null == string || "".equals(string.trim());
    }
}
